<h1><code ng:non-bindable="">$timeout</code>
<span class="hint">(service in module <code ng:non-bindable="">ng</code>
)</span>
</h1>
<div><a href="http://github.com/angular/angular.js/edit/master/src/ng/timeout.js" class="improve-docs btn btn-primary">Improve
    this doc</a>

    <h2 id="Description">Description</h2>

    <div class="description">
        <div class="ng-timeout-page"><p>Angular's wrapper for <code>window.setTimeout</code>. The <code>fn</code>
            function is wrapped into a try/catch
            block and delegates any exceptions to
            <a href="api/ng.$exceptionHandler"><code>$exceptionHandler</code></a> service.</p>

            <p>The return value of registering a timeout function is a promise, which will be resolved when
                the timeout is reached and the timeout function is executed.</p>

            <p>To cancel a timeout request, call <code>$timeout.cancel(promise)</code>.</p>

            <p>In tests you can use <a href="api/ngMock.$timeout"><code>$timeout.flush()</code></a> to
                synchronously flush the queue of deferred functions.</p></div>
    </div>
    <h2 id="Dependencies">Dependencies</h2>
    <ul class="dependencies">
        <li><code ng:non-bindable=""><a href="api/ng.$browser">$browser</a></code>
        </li>
    </ul>
    <h2 id="Usage">Usage</h2>

    <div class="usage">
        <pre class="prettyprint linenums">$timeout(fn[, delay][, invokeApply]);</pre>
        <h3 id="Parameters">Parameters</h3>
        <ul class="parameters">
            <li><code ng:non-bindable="">fn – {function()} – </code>

                <div class="ng-timeout-page"><p>A function, whose execution should be delayed.</p></div>
            </li>
            <li><code ng:non-bindable="">delay<i>(optional=0)</i> – {number=} – </code>

                <div class="ng-timeout-page"><p>Delay in milliseconds.</p></div>
            </li>
            <li><code ng:non-bindable="">invokeApply<i>(optional=true)</i> – {boolean=} – </code>

                <div class="ng-timeout-page"><p>If set to <code>false</code> skips model dirty checking, otherwise
                    will invoke <code>fn</code> within the <a href="api/ng.$rootScope.Scope#$apply"><code>$apply</code></a>
                    block.</p></div>
            </li>
        </ul>
        <h3 id="Returns">Returns</h3>

        <div class="returns"><code ng:non-bindable="">{Promise}</code>
            –
            <div class="ng-timeout-page"><p>Promise that will be resolved when the timeout is reached. The value this
                promise will be resolved with is the return value of the <code>fn</code> function.</p></div>
        </div>
    </div>
    <div class="member method"><h2 id="Methods">Methods</h2>
        <ul class="methods">
            <li><h3 id="cancel">cancel(promise)</h3>

                <div class="cancel">
                    <div class="ng-timeout-cancel-page"><p>Cancels a task associated with the <code>promise</code>. As a
                        result of this, the promise will be
                        resolved with a rejection.</p></div>
                    <h4 id="Parameters">Parameters</h4>
                    <ul class="parameters">
                        <li><code ng:non-bindable="">promise<i>(optional)</i> – {Promise=} – </code>

                            <div class="ng-timeout-cancel-page"><p>Promise returned by the <code>$timeout</code>
                                function.</p></div>
                        </li>
                    </ul>
                    <h4 id="Returns">Returns</h4>

                    <div class="returns"><code ng:non-bindable="">{boolean}</code>
                        –
                        <div class="ng-timeout-cancel-page"><p>Returns <code>true</code> if the task hasn't executed yet
                            and was successfully
                            canceled.</p></div>
                    </div>
                </div>
            </li>
        </ul>
    </div>
</div>
